//index.js
//获取应用实例
const app = getApp()
const mineService = require('../../service/mine.js');

Page({
  data: {
    title:"任务详情",
    id: "",
    detailInfo: {},
    list: [],
    queryParams: {
      page: 1,
      num: 10
    },
    isLast: false,
    dictionary:{
      statusList:{
        0:"审核中",
        1:"审核通过",
        2:"审核拒绝"
      }
    }
  },
  onLoad: function (options) {
    if (app.checkLogin()) {
      let id = options.id;
      this.setData({
        id: id
      })
      let d = {
        activityId: id,
        unionId: app.globalData.userinfo.unionId
      }
      this.getDetail(d);
      this.getContentList();
    }
    
  },
  goPublish(){
    const nagivatorList = {
      0:"/pages/release-dynamic/index",
      1:"/pages/release-video/index",
      2:"/pages/release-article/index",
      3:"/pages/release-question/index"
    }
    wx.navigateTo({
      url: `${nagivatorList[this.data.detailInfo['activityType']]}?id=${this.data.detailInfo['activityId']}`,
    })
  },
  getDetail(d) {
    mineService.getMineInviteDetail(d).then(res => {
      if (res.resCode == 0) {
        this.setData({
          detailInfo: res.object.activity
        });
      }
    })
  },
  getContentList() {
    let d = {
      ...this.data.queryParams,
      activityId:this.data.id,
      unionId: app.globalData.userinfo.unionId
    }
    mineService.getMineInviteDetailList(d).then(res => {
      if (res.resCode == 0) {
        if (!res.object.length) {
          this.setData({
            isLast: true
          });
          return false;
        }
        this.setData({
          list: [
            ...this.data.list,
            ...res.object
          ]
        });
      }
    })
  },
  onReachBottom() {
    if (this.data.isLast) return false;
    this.setData({
      queryParams: {
        page: ++this.data.queryParams.page,
        num: 10
      }
    })
    this.getContentList();
  }
})
